<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <el-form
        label-width="130px"
        :model="subjectForm"
        style="padding-right: 30px;"
        :rules="subjectInfosrules"
        ref="subjectForm"
      >
        <el-row>
          <el-col :span="13" style="margin-top: 27px;">
            <el-form-item class="form-item-release" label="规划名称 :">
              <span>{{name}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button size="small" type="success" style="margin-left: -50px;margin-top: 31px" @click="resultDetail()">规划详情</el-button>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item class="form-item-release" label="版本更新说明 :" prop="expertLeader">
              <el-input
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 4}"
                placeholder="请输入版本更新说明"
                v-model="subjectForm.updateReason"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="form-group-file">
        <span class="form-label-file">相关材料 :</span>
        <el-upload
          class="uploadFile"
          ref="upload"
          action="string"
          :http-request="fileUploadRequest"
          :on-preview="fileHandlePreview"
          :on-remove="fileHandleRemove"
          :auto-upload="true"
          :limit="1"
          :on-exceed="tipFileOne"
        >
          <el-button slot="trigger" size="small" type="primary">点击上传</el-button>
        </el-upload>
      </div>
      <div class="form-submit">
        <el-button type="primary" @click.stop="commitList()">上传</el-button>
        <el-button type="info" @click.stop="goBack()">关闭</el-button>
      </div>
      <el-dialog
        title="规划详情"
        :visible.sync="regDetailDialogFlag"
        width="70%"
        :before-close="regDetailClose">
        <div style="float: right;
                      font-size: 18px;
                      text-align: center;
                      margin-right: 51px;" v-if="pmuc">
          <span>规划编码：</span>
          <span style="display: inline-block">{{pmuc}}</span>
        </div>
        <div class="searchDetail">
          <bostech-detail :detail-data="detailData"></bostech-detail>
        </div>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="regDetailDialogFlag = false">确 定</el-button>
      </span>
      </el-dialog>
      <el-dialog
        title="评审意见详情"
        :visible.sync="opinionDetailDialogFlag"
        width="70%"
        :before-close="opinionDetailClose">
        <div class="searchDetail">
          <bostech-detail :detail-data="opinionDetailData"></bostech-detail>
        </div>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="opinionDetailDialogFlag = false">确 定</el-button>
      </span>
      </el-dialog>
    </div>
  </basic-container>
</template>
<script>
  import {uploadMake} from "@/api/make";
  import getDetailData from "@/mixins/getDetailData";
  import fileTypeMixin from "@/mixins/fileTypeMixin";
  import {resultDetail} from "@/api/planning/result";
  export default {
    name: "addMake",
    mixins:[fileTypeMixin,getDetailData()],
    created(){
      this.subjectForm.achievementId = this.$route.params.id
      this.name = this.$route.query.name
      this.getDetailData()
    },
    data(){
      return{
        headerData:{
          title:'版本上传'
        },
        subjectInfosrules:{},// 表单验证
        subjectForm: {
        },
        regDetailDialogFlag:false,
        name:'',// 规划名称
        fileType:'附件'
      }
    },
    methods:{
      goBack() {
        this.$router.go(-1);
      },
      commitList(){
        this.$confirm("确定上传版本么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$refs.subjectForm.validate(valid => {
            if (valid) {
              if(!this.fileTypeIds['附件']){
                this.$notify({
                  title: "提醒",
                  type: "warning",
                  message: "请选择相关材料，如已上传请稍候！",
                  duration: 2000
                });
                return;
              }
              this.subjectForm.fileId = this.getFileId(this.fileTypeIds['附件'])
              uploadMake(this.subjectForm).then(response => {
                if (response.data.code == 0) {
                  this.$notify({
                    title: "成功",
                    message: "上传成功",
                    type: "success",
                    duration: 2000
                  });
                  this.$router.go(-1);
                }
              })
            }
          })
        })
      },
      resultDetail(){
        this.regDetailDialogFlag = true
      },
      regDetailClose(){
        this.regDetailDialogFlag = false
      },
      // 获取规划详情信息
      getDetailData(){
        resultDetail(this.$route.params.id).then(response => {
          this.getresultDetail(response);
        })
      },
      async getresultDetail(response){
        if(response.data.code == '0') {
          var records = response.data.data
          this.name = records.title
          if(records.fileId!="" && records.fileId !=null) {
            this.multiplefiles = [];
            this.multiplefiles = await this.getfileinfopagetemp(records);
          }
          this.pmuc = records.pmuc
          this.getresultDetailDate(records)
        }
      },
      getfileinfopagetemp(records){
        return new Promise((resolve, reject) => {
          if(records.fileId!="" && records.fileId !=null){
            getfileinfopage(Object.assign({
              current: 1,
              size: 100,
              fileIds:records.fileId
            })).then(response => {
              var multiplefiles = response.data.data.records;
              resolve(multiplefiles);
            }).catch(
            )
          }
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
</style>
